<?php

/**
 * This is the model class for table "expense".
 *
 * The followings are the available columns in table 'expense':
 * @property string $ExpenseId
 * @property string $SRFNo
 * @property string $CustomerId
 * @property string $CategoryId
 * @property string $Receipt
 * @property integer $ExpenseType
 * @property string $Date
 * @property boolean $Billable
 * @property boolean $O_Night
 * @property string $ItemDescription
 * @property double $Total
 * @property string $Comment
 * @property string $From
 * @property string $To
 * @property double $Distance
 * @property double $Hour
 * @property double $AtPerHour
 * @property string $CreateAt
 * @property string $UpdateAt
 * @property boolean $Enabled
 * @property string $UserId
 * @property double $ExchangeRate
 * @property boolean $DeleteFlg
 * @property integer $CurrencyId
 *
 * The followings are the available model relations:
 * @property Comment[] $comments
 * @property Expensecategory $category
 * @property Users $user
 */
class Expense extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'expense';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('ExpenseType, CurrencyId', 'numerical', 'integerOnly'=>true),
			array('Total, Distance, Hour, AtPerHour, ExchangeRate', 'numerical'),
			array('SRFNo, From, To', 'length', 'max'=>255),
			array('CustomerId, CategoryId, UserId', 'length', 'max'=>19),
			array('Receipt, Date, Billable, O_Night, ItemDescription, Comment, CreateAt, UpdateAt, Enabled, DeleteFlg', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('ExpenseId, SRFNo, CustomerId, CategoryId, Receipt, ExpenseType, Date, Billable, O_Night, ItemDescription, Total, Comment, From, To, Distance, Hour, AtPerHour, CreateAt, UpdateAt, Enabled, UserId, ExchangeRate, DeleteFlg, CurrencyId', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'comments' => array(self::HAS_MANY, 'Comment', 'ObjectId'),
			'category' => array(self::BELONGS_TO, 'Expensecategory', 'CategoryId'),
			'user' => array(self::BELONGS_TO, 'Users', 'UserId'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ExpenseId' => 'Expense',
			'SRFNo' => 'Srfno',
			'CustomerId' => 'Customer',
			'CategoryId' => 'Category',
			'Receipt' => 'Receipt',
			'ExpenseType' => 'Expense Type',
			'Date' => 'Date',
			'Billable' => 'Billable',
			'O_Night' => 'O Night',
			'ItemDescription' => 'Item Description',
			'Total' => 'Total',
			'Comment' => 'Comment',
			'From' => 'From',
			'To' => 'To',
			'Distance' => 'Distance',
			'Hour' => 'Hour',
			'AtPerHour' => 'At Per Hour',
			'CreateAt' => 'Create At',
			'UpdateAt' => 'Update At',
			'Enabled' => 'Enabled',
			'UserId' => 'User',
			'ExchangeRate' => 'Exchange Rate',
			'DeleteFlg' => 'Delete Flg',
			'CurrencyId' => 'Currency',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('ExpenseId',$this->ExpenseId,true);
		$criteria->compare('SRFNo',$this->SRFNo,true);
		$criteria->compare('CustomerId',$this->CustomerId,true);
		$criteria->compare('CategoryId',$this->CategoryId,true);
		$criteria->compare('Receipt',$this->Receipt,true);
		$criteria->compare('ExpenseType',$this->ExpenseType);
		$criteria->compare('Date',$this->Date,true);
		$criteria->compare('Billable',$this->Billable);
		$criteria->compare('O_Night',$this->O_Night);
		$criteria->compare('ItemDescription',$this->ItemDescription,true);
		$criteria->compare('Total',$this->Total);
		$criteria->compare('Comment',$this->Comment,true);
		$criteria->compare('From',$this->From,true);
		$criteria->compare('To',$this->To,true);
		$criteria->compare('Distance',$this->Distance);
		$criteria->compare('Hour',$this->Hour);
		$criteria->compare('AtPerHour',$this->AtPerHour);
		$criteria->compare('CreateAt',$this->CreateAt,true);
		$criteria->compare('UpdateAt',$this->UpdateAt,true);
		$criteria->compare('Enabled',$this->Enabled);
		$criteria->compare('UserId',$this->UserId,true);
		$criteria->compare('ExchangeRate',$this->ExchangeRate);
		$criteria->compare('DeleteFlg',$this->DeleteFlg);
		$criteria->compare('CurrencyId',$this->CurrencyId);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Expense the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
